package inet.app.vod.adapter;

import inet.app.vod.activity.R;
import inet.app.vod.object.NewModel;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.inet.app.framework.bitmap.UniversalImageUtil;

public class NewCategoryAdapter extends ArrayAdapter<NewModel> {

	private Context mContext;
	private LayoutInflater mInflater;
	private List<NewModel> mItems;

	public NewCategoryAdapter(Context context, List<NewModel> items) {

		super(context, R.layout.item_listview_news_category);
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
		this.mItems = items;
	}

	@Override
	public int getCount() {
		return mItems.size();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder = new ViewHolder();
		final NewModel item = mItems.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(
					R.layout.item_listview_news_category, null);
			viewHolder.mTitle = (TextView) convertView
					.findViewById(R.id.title_text);
			viewHolder.mImage = (ImageView) convertView
					.findViewById(R.id.header_img);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.mTitle.setText(item.getTitle());
		UniversalImageUtil.getInstance(mContext).displayImage(item.getImg(),
				viewHolder.mImage);
		return convertView;

	}

	static class ViewHolder {
		protected TextView mTitle;
		protected ImageView mImage;
	}
}
